package com.juzishuke.margin.s1.config.web;

import com.juzishuke.margin.framework.web.VersionFilter;
import com.juzishuke.margin.framework.web.feign.VersionRequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.Connector;
import org.apache.coyote.AbstractProtocol;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
/**
 * @author : libo@juzishuke.com
 * @Title :
 * @Description :
 * @date : 2024/4/9 18:28
 * @since :1.0
 */
@Slf4j
@Configuration
public class WebConfig {

    //    @Bean
    //    public VersionFilter getVersionFilter() {
    //        return new VersionFilter();
    //    }
    //
    //    @Bean
    //    public VersionRequestInterceptor getVersionRequestInterceptor() {
    //        return new VersionRequestInterceptor();
    //    }
    @Bean
    public ServletWebServerFactory servletContainer() {
        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
        tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                ((AbstractProtocol) connector.getProtocolHandler()).setKeepAliveTimeout(1);
                ((AbstractProtocol) connector.getProtocolHandler()).setConnectionTimeout(1);
            }
        });
        return tomcat;
    }
}
